import { Application } from "egg";
import { hc } from "../hc";
import ToolsService from "./tools";
import SystemService from "./system";
import AudioService from "./audio";
import PersonService from "./person";
import ParamsService from "./params";
import RecordService from "./record";
import StrategyService from "./strategy";

const symbolToolInstance = Symbol("#toolsInstance");
const symbolSystemInstance = Symbol("#systemInstance");
const symbolAudioInstance = Symbol("#audioInstance");
const symbolParamsInstance = Symbol("#paramsInstance");
const symbolPersonInstance = Symbol("#personInstance");
const symbolRecordInstance = Symbol("#recordInstance");
const symbolStrategyInstance = Symbol("#strategyInstance");

export default class HCHttpService {
	constructor(protected device: hc.http.machine, protected app: Application) {}
	/** 通行策略接口 */
	get strategy() {
		if (!this[symbolStrategyInstance]) {
			this[symbolStrategyInstance] = new StrategyService(this.device, this.app);
		}
		return this[symbolStrategyInstance] as StrategyService;
	}
	/** 工具接口 */
	get tools() {
		if (!this[symbolToolInstance]) {
			this[symbolToolInstance] = new ToolsService(this.device, this.app);
		}
		return this[symbolToolInstance] as ToolsService;
	}
	/** 系统管理接口 */
	get system() {
		if (!this[symbolSystemInstance]) {
			this[symbolSystemInstance] = new SystemService(this.device, this.app);
		}
		return this[symbolSystemInstance] as SystemService;
	}
	/** 声音接口 */
	get audio() {
		if (!this[symbolAudioInstance]) {
			this[symbolAudioInstance] = new AudioService(this.device, this.app);
		}
		return this[symbolAudioInstance] as AudioService;
	}
	/** 记录接口 */
	get record() {
		if (!this[symbolRecordInstance]) {
			this[symbolRecordInstance] = new RecordService(this.device, this.app);
		}
		return this[symbolRecordInstance] as RecordService;
	}
	/** 人员接口 */
	get person() {
		if (!this[symbolPersonInstance]) {
			this[symbolPersonInstance] = new PersonService(this.device, this.app);
		}
		return this[symbolPersonInstance] as PersonService;
	}
	/** 设备参数接口 */
	get params() {
		if (!this[symbolParamsInstance]) {
			this[symbolParamsInstance] = new ParamsService(this.device, this.app);
		}
		return this[symbolParamsInstance] as ParamsService;
	}
}
